///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (2014) Alexander Stukowski
//
//  This file is part of OVITO (Open Visualization Tool).
//
//  OVITO is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  OVITO is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
///////////////////////////////////////////////////////////////////////////////

#include <plugins/pyscript/PyScript.h>
#include <core/animation/TimeInterval.h>
#include <core/animation/AnimationSettings.h>
#include "PythonBinding.h"

namespace PyScript {

using namespace boost::python;
using namespace Ovito;

BOOST_PYTHON_MODULE(PyScriptAnimation)
{
	docstring_options docoptions(true, false);

	class_<TimeInterval>("TimeInterval", init<>())
		.def(init<TimePoint>())
		.def(init<TimePoint, TimePoint>())
		.add_property("start", &TimeInterval::start, &TimeInterval::setStart)
		.add_property("end", &TimeInterval::end, &TimeInterval::setEnd)
		.add_property("isEmpty", &TimeInterval::isEmpty)
		.add_property("isInfinite", &TimeInterval::isInfinite)
		.add_property("duration", &TimeInterval::duration, &TimeInterval::setDuration)
		.def("setInfinite", &TimeInterval::setInfinite)
		.def("setEmpty", &TimeInterval::setEmpty)
		.def("setInstant", &TimeInterval::setInstant)
		.def("contains", &TimeInterval::contains)
		.def("intersect", &TimeInterval::intersect)
		.def("timeToSeconds", &TimeToSeconds)
		.def("secondsToTime", &TimeFromSeconds)
		.staticmethod("timeToSeconds")
		.staticmethod("secondsToTime")
		.add_static_property("infinite", &TimeInterval::infinite)
		.add_static_property("empty", &TimeInterval::empty)
		.setattr("TimeNegativeInfinity", TimeNegativeInfinity())
		.setattr("TimePositiveInfinity", TimePositiveInfinity())
		.def(self == TimeInterval())
		.def(self != TimeInterval())
	;

	ovito_class<AnimationSettings, RefTarget>(
			"Stores animation-related settings of the current :py:attr:`~ovito.DataSet`. You can access "
			"an instance of this class through the dataset's :py:attr:`~ovito.DataSet.anim` attribute."
			"\n\n"
			"Animation settings comprise the animation length (number of frames) and the current animation time. "
			"For example, to step through each animation frame and perform some action::"
			"\n\n"
			"    for frame in range(0, dataset.anim.last_frame + 1):\n"
			"        dataset.anim.current_frame = frame    # Jump to the animation frame.\n"
			"        performSomething()\n"
			"\n")
		.add_property("time", &AnimationSettings::time, &AnimationSettings::setTime)
		.add_property("animationInterval", make_function(&AnimationSettings::animationInterval, return_value_policy<copy_const_reference>()), &AnimationSettings::setAnimationInterval)
		.add_property("frames_per_second", &AnimationSettings::framesPerSecond, &AnimationSettings::setFramesPerSecond,
				"Controls the playback speed of the animation. This parameter also determines the playback speed of movie files generated by OVITO."
				"\n\n"
				":Default: 10\n")
		.add_property("ticksPerFrame", &AnimationSettings::ticksPerFrame, &AnimationSettings::setTicksPerFrame)
		.add_property("current_frame", &AnimationSettings::currentFrame, &AnimationSettings::setCurrentFrame,
				"The current animation frame. This parameter controls the position of the time slider in OVITO's main window "
				"and determines which animation frame is shown in the viewports."
				"\n\n"
				":Default: 0\n")
		.add_property("last_frame", &AnimationSettings::lastFrame, &AnimationSettings::setLastFrame,
				"The index of the last animation frame. You can change this property to set a new animation length."
				"\n\n"
				":Default: 0\n")
		.add_property("first_frame", &AnimationSettings::firstFrame, &AnimationSettings::setFirstFrame,
				"The index of the first animation frame."
				"\n\n"
				":Default: 0\n")
		.add_property("playbackSpeed", &AnimationSettings::playbackSpeed, &AnimationSettings::setPlaybackSpeed)
		.add_property("isAnimating", &AnimationSettings::isAnimating)
		.add_property("autoKeyMode", &AnimationSettings::autoKeyMode, &AnimationSettings::setAutoKeyMode)
		.add_property("isTimeChanging", &AnimationSettings::isTimeChanging)
		.def("frameToTime", &AnimationSettings::frameToTime)
		.def("timeToFrame", &AnimationSettings::timeToFrame)
		.def("snapTime", &AnimationSettings::snapTime)
		.def("timeToString", &AnimationSettings::timeToString)
		.def("stringToTime", &AnimationSettings::stringToTime)
		.def("jumpToAnimationStart", &AnimationSettings::jumpToAnimationStart)
		.def("jumpToAnimationEnd", &AnimationSettings::jumpToAnimationEnd)
		.def("jumpToNextFrame", &AnimationSettings::jumpToNextFrame)
		.def("jumpToPreviousFrame", &AnimationSettings::jumpToPreviousFrame)
		.def("startAnimationPlayback", &AnimationSettings::startAnimationPlayback)
		.def("stopAnimationPlayback", &AnimationSettings::stopAnimationPlayback)
	;
}

OVITO_REGISTER_PLUGIN_PYTHON_INTERFACE(PyScriptAnimation);

};
